// 与疫苗类似，不过有阴性/阳性两种结果
<template>
    <el-table v-loading="loading" :data="records" :default-sort="{ prop: 'time', order: 'descending' }"
        height="650px">
        <el-table-column prop="username" sortable label="用户名" />
        <el-table-column prop="time" sortable label="创建时间" />
        <el-table-column label="状态" >
            <template v-slot="scope">
                {{ code2Status(scope.row.result) }}
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template v-slot="scope">
                <el-button v-if="scope.row.result === 3" type="primary" @click="onChange(scope.row.id, scope.row.username, 2)">确认完成</el-button>
                <el-button type="success" @click="onChange(scope.row.id, scope.row.username, 0)">阴性</el-button>
                <el-button type="danger" @click="onChange(scope.row.id, scope.row.username, 1)">阳性</el-button>
            </template>
        </el-table-column>
    </el-table>
</template>

<script>
import {Request} from '../../utils/request'
import {ElMessage} from 'element-plus'

export default {
    name: 'NucleicCheck',
    data() {
        return {
            records: [],
            loading: true
        }
    },
    created() {this.reload()},
    methods: {
        reload() {
            this.loading = true
            Request({
                url: '/nucleic-acid-record',
                method: 'get'
            }).then(res => {
                this.records = res.record_list
                this.loading = false
            })
        },
        onChange(id, name, status) {
            Request({
                url: '/nucleic-acid-record',
                method: 'post',
                data: {result: status, username: name, record_id: id}
            }).then(res => {
                if(res === 'success') {
                    ElMessage({
                        message: '修改成功',
                        type: 'success'
                    })
                    this.reload()
                }
                else if (res) {
                    ElMessage({
                        message: '错误：' + res,
                        type: 'error'
                    })
                }
            })
        },
        code2Status(code) {
            if(code === 3) return '未完成'
            else if(code === 2) return '已完成'
            else if(code === 1) return '阳性'
            else return '阴性'
        }
    }
}
</script>